package com.dlyk.web;

import com.dlyk.model.CustomerRemark;
import com.dlyk.query.CustomerRemarkQuery;
import com.dlyk.result.R;
import com.dlyk.service.CustomerRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 客户备注
 */
@RestController
public class CustomerRemarkController {

    @Resource
    private CustomerRemarkService customerRemarkService;

    /**
     * 添加客户备注
     */
    @PostMapping("/api/customer/remark/add")
    public R addCustomerRemark(@RequestBody CustomerRemarkQuery customerRemarkQuery) {

        int add = customerRemarkService.addCustomerRemark(customerRemarkQuery);

        return add >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * 根据客户id查询客户的跟踪记录（注意逻辑删除字段的值）
     */
    @GetMapping("/api/customer/remark/list")
    public R loadCustomerRemarkList(Integer customerId,
                                    @RequestParam(value = "current", required = false) Integer current) {

        // required = false  表示非必须，这个参数也可以不传，不传参数，默认查询第一页
        if (current == null) {
            current = 1;
        }

        PageInfo<CustomerRemark> customerRemarkPageInfo = customerRemarkService.getCustomerRemarkListByPage(customerId, current);

        return R.OK(customerRemarkPageInfo);
    }

    /**
     * 编辑跟踪记录
     */
    @PutMapping("/api/customer/remark/edit")
    public R editCustomerRemark(@RequestBody CustomerRemarkQuery customerRemarkQuery) {

        int edit = customerRemarkService.editCustomerRemark(customerRemarkQuery);

        return edit >= 1 ? R.OK() : R.FAIL();
    }

    /**
     * 根据id删除跟踪记录
     */
    @DeleteMapping("/api/customer/remark/remove/{id}")
    public R removeCustomerRemark(@PathVariable Integer id) {

        int remove = customerRemarkService.removeCustomerRemarkById(id);

        return remove >= 1 ? R.OK() : R.FAIL();
    }

}

